package com.imagepreview.plugin;

import androidx.annotation.NonNull;

import io.flutter.embedding.engine.plugins.FlutterPlugin;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;

/**
 * 项目插件管理，用于在 Flutter 应用中集成原生 Android 或 iOS 功能。
 * 通过实现 FlutterPlugin 接口，你可以在 Flutter 应用中调用原生代码，从而实现一些 Flutter 本身不支持的功能，
 * 比如访问设备摄像头、文件系统、传感器等。
 */
public class DevicePlugin implements FlutterPlugin, MethodChannel.MethodCallHandler {
    private MethodChannel channel;

    @Override
    public void onAttachedToEngine(@NonNull FlutterPluginBinding binding) {
        // flutter侧通过  static const MethodChannel _channel = MethodChannel('com.example.myapp/channel'); 去调用方法
        channel = new MethodChannel(binding.getBinaryMessenger(), "com.imagepreview.plugin/device_channel");
        channel.setMethodCallHandler(this);
    }

    @Override
    public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) {
        channel.setMethodCallHandler(null);
    }

    @Override
    public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result result) {
        if (call.method.equals("getPlatformVersion")) {
            result.success("Android " + android.os.Build.VERSION.RELEASE);
        } else {
            result.notImplemented();
        }
    }
}
